<?php
/**
 * 
 * 管理员类
 * @author Administrator
 *
 */
class osgh_admin_index_tbl_cls extends pl_db_opt_cls
{
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		
		global $_db_name;
		$this->setDbName($_db_name);
		$this->setTblName('osgh_admin_index_tbl');
	}
	
	/*
	 * 添加管理员
	 *
	 * @param array $data
	 * @return int
	 */
	public function addAdminIndex($data)
	{
		return $this->insert($data, 'IGNORE');
	}
	
	/**
	 * 
	 * 更新管理员信息
	 * @param array $data
	 * @param int $admin_id
	 */
	public function updateAdminIndex(array $data, $where_str)
	{
		return $this->update($data, $where_str);
	}
	
	
	/*
	 * 删除管理员
	 *
	 * @param array $admin_id
	 * @return bool
	 */
	public function delAdminIndex($admin_id)
	{
		$user_id = intval($admin_id);
		if($admin_id < 1) return false;
		$where_str = "admin_id='{$admin_id}'";
		
	//	$data = array('is_available' => 0,  'cinemaid' => '');
		$data = array('is_available' => 0);
		return $this -> update($data, $where_str);
	}
	
	/**
	 * 获取单个管理员信息
	 *
	 * @param int $admin_id
	 * @param string $select_str
	 * @return array
	 */
	public function getAdminIndexInfo($admin_id, $select_str = '*')
	{
		$admin_id = intval($admin_id);
		$where_str = "admin_id = {$admin_id}";
		return $this->getRow($where_str, $select_str);
	}
	
	
	/**
	 * 获取管理员列表
	 * 
	 * @param bool $b_select_count
	 * @param string $where_str    查询条件
	 * @param string $order_by
	 * @param string $limit
	 * @return array
	 */
	public function getAdminIndexList($b_select_count = false, $where_str = '', $order_by = '', $limit = '')
	{
		$sql = "SELECT * FROM {$this->db_name}.{$this->tbl_name}";
		
		$sql_where = '';
		$sql_where_sp = '';
		
		if( strlen($where_str) > 0 )
		{
			$sql_where_sp = strlen($sql_where)>0?' AND ':'';
			$sql_where = $sql_where . $sql_where_sp . $where_str;
		}
		
		if ( strlen($sql_where) > 0 )
		{
			$sql .= " WHERE " . $sql_where;
		}
		
		if ( $b_select_count == true )
		{
			//统计记录数
			$tmp = $this->getList($b_select_count, $sql);
			return $tmp;
		}
		
		return $this->getList($b_select_count, $sql, $order_by, $limit);
	}	
	
}